import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },

    {
        path: '/404',
        component: () =>
            import ('@/views/404'),
        hidden: true
    },

    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [{
            path: 'dashboard',
            name: 'Dashboard',
            component: () =>
                import ('@/views/dashboard/index'),
            meta: { title: '首页', icon: 'dashboard' }
        }]
    }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [{
        path: '/system',
        component: Layout,
        meta: { title: '系统管理员菜单', icon: 'dashboard', roles: ['system'] },
        children: [{
                path: 'phone',
                name: '客服电话管理',
                component: () =>
                    import ('@/views/phone/phone'),
                meta: { title: '客服电话管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'classUser',
                name: '会员管理',
                component: () =>
                    import ('@/views/classUser/classUser'),
                meta: {
                    title: '会员管理',
                    icon: 'dashboard',
                    roles: ['system']
                }
            },
            {
                path: 'consoleUser',
                name: '管理员用户管理',
                component: () =>
                    import ('@/views/consoleUser/consoleUser'),
                meta: { title: '管理员用户管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'creditBank',
                name: '信用卡银行管理',
                component: () =>
                    import ('@/views/creditBank/creditBank'),
                meta: { title: '信用卡银行管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'creditApply',
                name: '信用卡申请管理',
                component: () =>
                    import ('@/views/creditApply/creditApply'),
                meta: { title: '信用卡申请管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'class',
                name: '服务项目管理',
                component: () =>
                    import ('@/views/class/class'),
                meta: { title: '服务项目管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'classType',
                name: '行业分类',
                component: () =>
                    import ('@/views/classType/classType'),
                meta: { title: '行业分类', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'orders',
                name: '订单管理',
                component: () =>
                    import ('@/views/orders/orders'),
                meta: { title: '订单管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'financial',
                name: '对账管理',
                component: () =>
                    import ('@/views/financial/duizhang'),
                redirect: '/system/financial/jiaoyiduizhang',
                meta: { title: '对账管理', icon: 'dashboard', roles: ['system'] },
                children: [{
                        path: 'jiaoyiduizhang',
                        name: '交易对账',
                        component: () =>
                            import ('@/views/financial/jiaoyiduizhang'),
                        meta: { title: '交易对账', icon: 'dashboard', roles: ['system'] }
                    }, {
                        path: 'qingsuanduizhang',
                        name: '清算对账',
                        component: () =>
                            import ('@/views/financial/qingsuanduizhang'),
                        meta: { title: '清算对账', icon: 'dashboard', roles: ['system'] }
                    },
                    {
                        path: 'duizhangDownLoad',
                        name: '对账下载',
                        component: () =>
                            import ('@/views/financial/duizhangDownLoad'),
                        meta: { title: '对账下载', icon: 'dashboard', roles: ['system'] }
                    }

                ]
            },
            {
                path: 'orgType',
                name: '机构分类',
                component: () =>
                    import ('@/views/orgType/orgType'),
                meta: { title: '机构分类', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'org',
                name: '品牌管理',
                component: () =>
                    import ('@/views/org/org'),
                meta: { title: '品牌管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'campus',
                name: '机构管理',
                component: () =>
                    import ('@/views/campus/campus'),
                meta: { title: '机构管理', icon: 'dashboard', roles: ['system'] }
            },

            {
                path: 'refund',
                name: '退款管理',
                component: () =>
                    import ('@/views/refund/refund'),
                meta: { title: '退款管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'stage',
                name: '分期管理',
                component: () =>
                    import ('@/views/stage/stage'),
                meta: { title: '分期管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'bank',
                name: '银行管理',
                component: () =>
                    import ('@/views/bank/bank'),
                meta: { title: '银行管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'ad',
                name: '广告管理',
                component: () =>
                    import ('@/views/ad/ad'),
                meta: { title: '广告管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'recommend',
                name: '代理人管理',
                component: () =>
                    import ('@/views/recommend/recommend'),
                meta: { title: '代理人管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'agentApplication',
                name: '等级提升申请管理',
                component: () =>
                    import ('@/views/agentApplication/agentApplication'),
                meta: { title: '等级提升申请管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'business',
                name: '业务管理',
                component: () =>
                    import ('@/views/business/business'),
                meta: { title: '业务管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'rebateLevel',
                name: '分润设置',
                component: () =>
                    import ('@/views/rebateLevel/rebateLevel'),
                meta: { title: '分润设置', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'publicityPictures',
                name: '宣传图片设置',
                component: () =>
                    import ('@/views/publicityPictures/publicityPictures'),
                meta: { title: '宣传图片设置', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'cooperation',
                name: '合作记录管理',
                component: () =>
                    import ('@/views/cooperation/cooperation'),
                meta: { title: '合作记录管理', icon: 'dashboard', roles: ['system'] }
            },
            {
                path: 'statistic',
                name: '统计分析',
                component: () =>
                    import ('@/views/statisic/AdminStatistic'),
                meta: { title: '统计分析', icon: 'dashboard', roles: ['system'] }
            }
            // {
            //   path: 'test',
            //   name: '测试',
            //   component: () => import('@/views/test/test'),
            //   meta: { title: '测试', icon: 'dashboard', roles: ['system'] }
            // }
        ]
    },

    {
        path: '/campus',
        component: Layout,
        meta: { title: '机构管理员菜单', icon: 'dashboard', roles: ['campus'] },
        children: [{
                path: 'my',
                name: '我的机构管理',
                component: () =>
                    import ('@/views/campus/oneCampus'),
                meta: { title: '我的机构管理', icon: 'dashboard', roles: ['campus'] }
            },
            {
                path: 'class',
                name: '服务项目管理',
                component: () =>
                    import ('@/views/class/classByCampus'),
                meta: { title: '服务项目管理', icon: 'dashboard', roles: ['campus'] }
            },
            {
                path: 'orders',
                name: '机构订单管理',
                component: () =>
                    import ('@/views/orders/campusOrders'),
                meta: { title: '机构订单管理', icon: 'dashboard', roles: ['campus'] }
            },
            {
                path: 'statistic',
                name: '机构统计分析',
                component: () =>
                    import ('@/views/statisic/campusStatistic'),
                meta: { title: '机构统计分析', icon: 'dashboard', roles: ['campus'] }
            }
        ]
    },

    {
        path: '/recommend',
        component: Layout,
        meta: { title: '代理人菜单', icon: 'dashboard', roles: ['recommend'] },
        children: [{
                path: 'info',
                name: '个人信息',
                component: () =>
                    import ('@/views/consoleUser/userInfo'),
                meta: { title: '个人信息', icon: 'dashboard', roles: ['recommend'] }
            },
            {
                path: 'add',
                name: '代理人管理',
                component: () =>
                    import ('@/views/consoleUser/recommend'),
                meta: { title: '代理人管理', icon: 'dashboard', roles: ['recommend'] }
            },
            {
                path: 'business',
                name: '业务管理',
                component: () =>
                    import ('@/views/business/reBusiness'),
                meta: { title: '业务管理', icon: 'dashboard', roles: ['recommend'] }
            },
            {
                path: 'zxbusiness',
                name: '直辖业务管理',
                component: () =>
                    import ('@/views/business/zxBusiness'),
                meta: { title: '直辖业务管理', icon: 'dashboard', roles: ['recommend'] }
            },
            // {
            //   path: 'agentApplication',
            //   name: '等级提升申请',
            //   component: () => import('@/views/agentApplication/addAgentApplication'),
            //   meta: { title: '等级提升申请', icon: 'dashboard', roles: ['recommend'] }
            // },
            {
                path: 'myAgentApplication',
                name: '等级提升申请管理',
                component: () =>
                    import ('@/views/agentApplication/myAgentApplication'),
                meta: { title: '我的等级提升申请', icon: 'dashboard', roles: ['recommend'] }
            },
            {
                path: 'org',
                name: '品牌管理',
                component: () =>
                    import ('@/views/org/orgByRe'),
                meta: { title: '品牌管理', icon: 'dashboard', roles: ['recommend'] }
            }, {
                path: 'campus',
                name: '机构管理',
                component: () =>
                    import ('@/views/campus/campusByRe'),
                meta: { title: '机构管理', icon: 'dashboard', roles: ['recommend'] }
            }
            // {
            //   path: 'orders',
            //   name: '代理人订单',
            //   component: () => import('@/views/orders/recommendOrders'),
            //   meta: { title: '订单管理', icon: 'dashboard', roles: ['recommend'] }
            // },
            // {
            //   path: 'statistic',
            //   name: '统计分析',
            //   component: () => import('@/views/statisic/RecommendStatistic'),
            //   meta: { title: '统计分析', icon: 'dashboard', roles: ['recommend'] }
            // }
        ]
    },

    {
        path: '/org',
        component: Layout,
        meta: { title: '品牌管理员菜单', icon: 'dashboard', roles: ['org'] },
        children: [{
                path: 'myorg',
                name: '我的品牌管理',
                component: () =>
                    import ('@/views/org/myOrg'),
                meta: { title: '我的品牌管理', icon: 'dashboard', roles: ['org'] }
            },
            {
                path: 'mycampus',
                name: '机构管理',
                component: () =>
                    import ('@/views/campus/myCampus'),
                meta: { title: '机构管理', icon: 'dashboard', roles: ['org'] }
            },
            {
                path: 'class',
                name: '服务项目管理',
                component: () =>
                    import ('@/views/class/classByOrg'),
                meta: { title: '服务项目管理', icon: 'dashboard', roles: ['org'] }
            },
            {
                path: 'orders',
                name: '订单管理',
                component: () =>
                    import ('@/views/orders/orgOrders'),
                meta: { title: '订单管理', icon: 'dashboard', roles: ['org'] }
            },
            {
                path: 'statistic',
                name: '统计分析',
                component: () =>
                    import ('@/views/statisic/OrgStatistic'),
                meta: { title: '统计分析', icon: 'dashboard', roles: ['org'] }
            }
        ]
    },

    {
        path: '/caiwu',
        component: Layout,
        meta: { title: '财务菜单', icon: 'dashboard', roles: ['caiwu'] },
        children: [{
                path: 'caiwu',
                name: '财务管理',
                component: () =>
                    import ('@/views/financial/financial'),
                meta: { title: '财务管理', icon: 'dashboard', roles: ['caiwu'] }
            },
            {
                path: 'financial',
                name: '对账管理',
                component: () =>
                    import ('@/views/financial/duizhang'),
                redirect: '/system/financial/jiaoyiduizhang',
                meta: { title: '对账管理', icon: 'dashboard', roles: ['caiwu'] },
                children: [{
                        path: 'jiaoyiduizhang',
                        name: '交易对账',
                        component: () =>
                            import ('@/views/financial/jiaoyiduizhang'),
                        meta: { title: '交易对账', icon: 'dashboard', roles: ['caiwu'] }
                    }, {
                        path: 'qingsuanduizhang',
                        name: '清算对账',
                        component: () =>
                            import ('@/views/financial/qingsuanduizhang'),
                        meta: { title: '清算对账', icon: 'dashboard', roles: ['caiwu'] }
                    },
                    {
                        path: 'duizhangDownLoad',
                        name: '对账下载',
                        component: () =>
                            import ('@/views/financial/duizhangDownLoad'),
                        meta: { title: '对账下载', icon: 'dashboard', roles: ['caiwu'] }
                    }

                ]
            }
        ]
    },

    {
        path: '/human',
        component: Layout,
        meta: { title: '人事菜单', icon: 'dashboard', roles: ['human'] },
        children: [{
            path: 'agentAudit',
            name: '代理人审核',
            component: () =>
                import ('@/views/agentAudit/agentAudit'),
            meta: { title: '代理人审核', icon: 'dashboard', roles: ['human'] }
        }]
    },
    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }

]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router